package com.jkgh.remedium;

import java.util.HashMap;
import java.util.Map;

import com.jkgh.asin.StateMachine;
import com.jkgh.remedium.objects.RemediumMethodObject;

public abstract class RemediumHost {

	private final Map<Integer, RemediumMethodObject> methodObjects;
	private final Map<Integer, Returner<? extends Object>> calls;
	
	private int callIDGenerator;

	public RemediumHost() {
		this.methodObjects = new HashMap<Integer, RemediumMethodObject>();
		this.calls = new HashMap<Integer, Returner<? extends Object>>();
		this.callIDGenerator = 0;
	}
	
	public RemediumMethodObject getMethodObject(int objectID) {
		return methodObjects.get(objectID);
	}

	public void registerMethodObject(int objectID, RemediumMethodObject object) {
		methodObjects.put(objectID, object);
	}

	public abstract StateMachine getMachine();

	public int registerCall(Returner<? extends Object> returner) {
		int callID = nextCallID();
		calls.put(callID, returner);
		return callID;
	}

	private int nextCallID() {
		return callIDGenerator++;
	}

}
